<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
if (isset($FullDomain) && defined(HEIDOMAIN)) {
    require 'UDR.class.php';
    $db = new PDO(PDOTEXT, DBUSER, DBPASSWD);
    $result = $db->prepare('SELECT * FROM data WHERE FullDomain=:FullDomain LIMIT 1');
    if ($result->execute(array(':FullDomain' => $FullDomain))) {
        $DataArr = $result->fetchAll(PDO::FETCH_ASSOC)[0];
        if ($DataArr['Done'] != 1) {
            $result = $db->prepare('SELECT * FROM user_info WHERE uid=:uid LIMIT 1');
            if ($result->execute(array(':uid' => $DataArr['uid']))) {
                $UserDataArr = $result->fetchAll(PDO::FETCH_ASSOC)[0];
                $newObject = new UpdateDomainRecord($UserDataArr['AccessKeyId'], $UserDataArr['AccessKeySecret'], UDR);
                $CurlAliyun = $newObject->execute($DataArr['RecordId'], $DataArr['RR'], $DataArr['Type'], $DataArr['Value']);
                CurlAliyun($CurlAliyun);
                $nowtime = date('Y-m-d H:i:s', time());
                $result = $db->prepare('UPDATE data SET Done=1, DoTime=:DoTime WHERE (FullDomain=:FullDomain)');
                if ($result->execute(array(':DoTime' => $nowtime, ':FullDomain' => $FullDomain))) {
                    require '../Mail/DoHD_mail.php';
                    SendMail($FullDomain, $UserDataArr["email"], $nowtime, $DataArr['Value']);
                    return True;
                }
            }
        } else {
            exit();
        }
    } else {
        exit();
    }
}

